package com.example.base.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.core.widget.NestedScrollView;

/**
 * Author by zhengbenying
 * Email zhengbenying@hikvison.com
 * Company 杭州海康威视数字技术股份有限公司
 * Date on 2018/9/11
 */
public class JudgeNestedScrollView extends NestedScrollView {

    private boolean isNeedScroll = false;

    public JudgeNestedScrollView(@NonNull Context context) {
        super(context);
    }

    public JudgeNestedScrollView(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    public boolean onInterceptTouchEvent(MotionEvent ev) {
        switch (ev.getAction()) {
            case MotionEvent.ACTION_MOVE:
                return isNeedScroll;
        }
        return super.onInterceptTouchEvent(ev);
    }

    public void setNeedScroll(boolean needScroll){
        this.isNeedScroll = needScroll;
    }
}
